package com.stu.stusystem.controller.system;

import com.github.pagehelper.PageInfo;
import com.stu.stusystem.common.ApiResult;
import com.stu.stusystem.service.system.StuClassService;
import com.stu.stusystem.service.system.dto.StuClassDTO;
import com.stu.stusystem.service.system.dto.StuClassQuery;
import com.stu.stusystem.service.system.vo.StuClassVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author: cxt
 * @time: 2021/3/24
 */
@Api(tags = "班级管理")
@RestController
@RequestMapping("/stu/class")
public class StuClassController {

    private StuClassService stuClassService;

    @ApiOperation("分页查询")
    @GetMapping("/get")
    public PageInfo<StuClassVO> getStuClassPage(StuClassQuery query) {
        return this.stuClassService.getStuClassPage(query);
    }

    @ApiOperation("修改班级信息")
    @PutMapping("/update")
    public ApiResult<String> updateStuClass(@RequestBody StuClassDTO dto) {
        this.stuClassService.updateStuClass(dto);
        return ApiResult.success();
    }

    @ApiOperation("删除班级")
    @DeleteMapping("/delete")
    public ApiResult<String> deleteStuClass(@RequestParam("id") String id) {
        this.stuClassService.deleteStuClass(id);
        return ApiResult.success();
    }

    @ApiOperation("新增班级")
    @PostMapping("/add")
    public ApiResult<String> saveStuClass(@RequestBody StuClassDTO dto) {
        this.stuClassService.saveStuClass(dto);
        return ApiResult.success();
    }

    @ApiOperation("树形班级结构")
    @GetMapping("/get/treeData")
    public List<Object> getStuClassTreeData() {
        return this.stuClassService.getStuClassTreeData();
    }

    @ApiOperation("查询全部的系和学院")
    @GetMapping("/non/class")
    public HashMap<String, ArrayList<StuClassVO>> getNonClass() {
        return this.stuClassService.getNonClass();
    }

    @Autowired
    public void setStuClassService(StuClassService stuClassService) {
        this.stuClassService = stuClassService;
    }
}
